/*
 * =====================================================================================
 *
 *       Filename:  string.cpp
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2012/3/2 23:47:43
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  YOUR NAME (), 
 *   Organization:  
 *
 * =====================================================================================
 */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int mystrcmp(char *a, char *b){
  int i = 0;
  while(*(a + i) != '\0' && *(b + i) != '\0' && *(a + i) == *(b + i))
      i++;
  if( *(a + i) == '\0' && *(b + i) == '\0')
      return 0;
  return *(a + i) - *(b + i);
}

int find(char *src[], char *temp, int begin, int end){
  int m = (begin + end) / 2;
  if(begin > end)
    return -1;
  if(mystrcmp(src[m], temp) == 0)
    return m;
  else if(mystrcmp(src[m], temp) >0)
    return find(src, temp, begin, m - 1);
  else
    return find(src, temp, m + 1, end);  
}

int findInt(int src[],int temp, int begin, int end){
  int m = (begin + end) / 2;
  if(begin > end)
    return -1;
  if(src[m] == temp) 
    return m;
  else if(src[m] > temp)
    return findInt(src, temp , begin , m - 1);
  else
    return findInt(src, temp, m + 1, end);
}
int main(){
    char *a[]={"abc","abcf","ab"};
    char b[] = "abcf";
//    int x[]={1,2,3,4,5,6,7,8,9};
   printf("%d",find(a,b,0,2));
//    printf("%d\n",findInt(x,6,0,8));
}

